
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

/**
 * ./led_test /dev/my_led on
 * ./led_test /dev/my_led off
*/
int main(int argc, char **argv) 
{
    int fd;
    char status = 0;

    if (argc != 3) 
    {
        printf("Usage: %s <dev> <on | off>", argv[0]);
        return -1;
    }

    fd = open(argv[1], O_RDWR);
    if (fd == -1 )
    {
        printf("can not open file %s\n", argv[1]);
        return -1;
    }

    if (strcmp(argv[2], "on")) 
    {
        status = 1
    }
    write(fd, &status, 1);

    close(fd);
    
    return 0;
}